package com.aiyige.share.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.share.model.ShareContactItem;
import com.aiyige.utils.GlideUtil;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ShareContactAdapter extends BaseQuickAdapter<ShareContactItem, ShareContactAdapter.ViewHolder> {
    public ShareContactAdapter() {
        super(R.layout.share_contact_item, new LinkedList<ShareContactItem>());
    }

    @Override
    protected void convert(ViewHolder helper, ShareContactItem item) {
        helper.bindData(item);
    }


    public class ViewHolder extends BaseViewHolder {
        @BindView(R.id.shareIv)
        ImageView shareIv;
        @BindView(R.id.shareTv)
        TextView shareTv;
        @BindView(R.id.moreTv)
        TextView moreTv;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void bindData(ShareContactItem data) {
            switch (data.getType()) {
                case ShareContactItem.TYPE_MORE:
                    shareTv.setVisibility(View.INVISIBLE);
                    shareIv.setVisibility(View.INVISIBLE);
                    moreTv.setVisibility(View.VISIBLE);
                    break;
                case ShareContactItem.TYPE_NORMAL:
                    moreTv.setVisibility(View.INVISIBLE);
                    shareTv.setVisibility(View.VISIBLE);
                    shareIv.setVisibility(View.VISIBLE);
                    GlideUtil.with(itemView.getContext())
                            .loadAvatar(data.getAvatar())
                            .into(shareIv);
                    shareTv.setText(data.getName());
                    break;
            }
        }
    }

}
